﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>数据字典表</title>
    <script language="JavaScript" src="../Comm/JScript.js" type="text/javascript" ></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <link href="../Scripts/easyUI/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <script src="../Scripts/CreateControl.js" type="text/javascript"></script>
     <base target="_self" /> 
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" >

        CreatePrintViewerEx("0", "0", "", "", false, "<param name=BorderStyle value=1>");
         
        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });

        //初始化数据.
        function InitPage() {

            var nodeID = GetQueryString("FK_Node");

            //初始化表格.
            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=Print_Init&FK_Node=" + nodeID + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = JSON.parse(data);

                    //增加处理.
                    for (var i = 0; i < data.length; i++) {

                        var bill = data[i];

                        var newRow = "";

                        newRow = "<tr ><td class=Idx>" + i + "</td>";
                        newRow += "<td>" + bill.BillNo + "</td>";
                        newRow += "<td>" + bill.BillName + "</td>";
                        newRow += "<td>";

                        if (bill.BillName.indexOf('.grf') == -1) {
                            newRow += "<a href='javascript:btnPreview_onclick(\"" + fileName + "\")' >打印</a>";
                            //this.Pub1.AddTD("");
                        } else {
                           // this.Pub1.AddTD("<a href='Print.aspx?FK_Node=" + this.FK_Node + "&FID=" + this.FID + "&FK_Flow=" + this.FK_Flow + "&WorkID=" + this.WorkID + "&BillIdx=" + fileIdx + "' target=_blank >打印</a>");
                         
                        }
                        newRow += "</td>";
                        newRow += "</tr>";

                        $("#Table1 tr:last").after(newRow);
                    }
                }
            });
        }


        function btnPreview_onclick(name) {


            try {
                var FK_MapData = "";
                var frmParas = name.split('.');
                if (frmParas.length == 3 || frmParas.length == 2) {
                    FK_MapData = frmParas[0];
                }

                var ReportViewer = document.getElementById("ReportViewer");
                var Report = ReportViewer.Report;
                var arges = new RequestArgs();
                Report.LoadFromURL("../../DataUser/CyclostyleFile/FlowFrm/" + arges.FK_Flow + "/" + arges.FK_Node + "/" + encodeURI(name));

                //装载主表
                var pageUrl = "../WorkOpt/GridData.ashx?WorkID=" + arges.WorkID + "&FK_Flow=" + arges.FK_Flow + "&FK_Node=" + arges.FK_Node + "&FK_MapData=" + FK_MapData + "&DoType=4&GetType=MainPage";
                Report.LoadDataFromURL(pageUrl);
                //获取明细表编号
                var json_data = { "WorkID": arges.WorkID, "FK_Flow": arges.FK_Flow, "FK_Node": arges.FK_Node, FK_MapData: FK_MapData, "DoType": "3" };
                $.ajax({
                    type: "get",
                    url: "../WorkOpt/GridData.ashx",
                    data: json_data,
                    async: true,
                    beforeSend: function (XMLHttpRequest, fk_mapExt) {
                        //ShowLoading();
                    },
                    success: function (data, textStatus) {
                        if (data != null) {
                            //装载明细表
                            var resultData = eval("(" + data + ")");
                            var arges = new RequestArgs();
                            for (var idx in resultData) {
                                try {
                                    var childReport = ReportViewer.Report.ControlByName(resultData[idx].Name);
                                    if (childReport == "" || childReport == null) {
                                        alert("没有在模版中找到相应的子报表");
                                    } else {
                                        childReport.AsSubReport.Report.LoadDataFromURL("../WorkOpt/GridData.ashx?WorkID=" + arges.WorkID + "&FK_Flow=" + arges.FK_Flow + "&FK_Node=" + arges.FK_Node + "&DoType=4&GetType=" + resultData[idx].Name);
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                            }
                            //装载图片
                            json_data = { "WorkID": arges.WorkID, "FK_Flow": arges.FK_Flow, "FK_Node": arges.FK_Node, "DoType": "6" };
                            $.ajax({
                                type: "get",
                                url: "../WorkOpt/GridData.ashx",
                                data: json_data,
                                async: true,
                                beforeSend: function (XMLHttpRequest, fk_mapExt) {
                                    //ShowLoading();
                                },
                                success: function (PhotoData, textStatus) {

                                    var dataPhoto = eval("(" + PhotoData + ")");

                                    for (var index in dataPhoto) {
                                        try {
                                            Report.ControlByName(dataPhoto[index].Name).AsPictureBox.LoadFromFile(dataPhoto[index].Value);
                                        }
                                        catch (e) {

                                        }
                                    }
                                },
                                complete: function (XMLHttpRequest, textStatus) {
                                    //alert('HideLoading');
                                    //HideLoading();
                                },
                                error: function () {
                                    alert('加载图片出现异常！！.');
                                    //请求出错处理
                                }
                            });
                        } else {
                            alert('加载数据出现异常!');
                        }
                        //最后显示
                        Report.PrintPreview(true);
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //    alert('HideLoading');
                        //HideLoading();
                    },
                    error: function () {
                        alert('error when load data.');
                        //请求出错处理
                    }
                });

            } catch (ex) {
                alert(ex.message);
            }
        }

        //获取参数
        var RequestArgs = function () {
            this.WorkID = GetQueryString("WorkID");
            this.FK_Flow = GetQueryString("FK_Flow");
            this.FK_Node = GetQueryString("FK_Node");
            if (this.FK_Node) {
                while (this.FK_Node.substring(0, 1) == '0') this.FK_Node = this.FK_Node.substring(1);
                this.FK_Node = this.FK_Node.replace('#', '');
            }
            this.FID = GetQueryString("FID");
        }
              
     </script>
</head>
<body>

<table id="Table1" style=" width:98%; ">
<caption>单据打印</caption>
<tr>
<th>序</th>
<th>编号</th>
<th>名称</th>
<th>打印</th>
</tr>
</table>

<div id="Msg"></div>

</body>
</html>
